<?php
namespace app\admin\model;

use think\Db;
use think\facade\Config;
use think\Model;

class TestOrder extends Model
{
    protected $table = 'bus_test_plat_order';

    public static function getTestOrders($request)
    {
        $where = [];
        if($request['create_time'] != ''){
            $where[] = ['po.create_time', '>', $request['create_time']];
        }

        if($request['end_time'] != ''){
            $where[] = ['po.create_time', '<', $request['end_time']];
        }

        if($request['cid'] != ''){
            $where[] = ['po.cid', '=', $request['cid']];
        }

        if($request['isp_host'] != ''){
            $where[] = ['op.isp_host', '=', $request['isp_host']];
        }

        if($request['platId'] != ''){
            $where[] = ['po.plat_id', '=', $request['platId']];
        }

        if($request['phone'] != ''){
            $where[] = ['op.phone', '=', $request['phone']];
        }
        return self::alias('po')
                ->field('po.*,op.phone,bc.company_name,bp.platfrom')
                ->join('bus_test_order_phone op','po.id = op.test_order_table_id','LEFT')
                ->join('bus_channel bc','bc.channel_id = po.cid','LEFT')
                ->join('bus_platfrom bp','bp.plat_id = po.plat_id','LEFT')
                ->where($where)
                ->group('po.id')
                ->paginate($request['limit'], false, $request)
                ->each(function($item, $key){
                    $item->company_name = $item->cid . '/' . $item->company_name;
                    $item->plat_ = $item->plat_id . '/' . $item->platfrom;
                    $item->sms_all_total = '<a class="test_order" href="javascript:;" style="text-decoration:underline;color:#5A98DE;" title="点击查看详情" order-id="' . $item->id . '">查看('.$item->sms_all_total.')</a>';
                })
                ->toArray();
    }

}
